<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.1.0.js"></script>
<script type="text/javascript">
 $(function(){
	$("#writeF").submit(function(){
		if($("#content").val()==""){
			alert("내용을 입력하세요");
			return false;
		}
		if($("#title").val()==""){
			alert("제목을 입력하세요");
			return false;
		}
	});
	
	var count=0;
	
	$("#letterCount").html(count); 
	$("#content").keyup(function(){
		var str="";
		str=$("#content").val();
		$("#letterCount").html(str.length); 
	});
		
	 $("#fileDelete").click(function(){
		 if($("#fileUpload").val()==""){
			 alert("등록된 파일이 없습니다.");
		 }else{
			 if(confirm("파일을 삭제하시겠습니까?")){
				 
				 $("#fileUpload").val("");
			 }
		 }
	 });
	 
	 
	 $("#fileDelete1").click(function(){
		 if($("#fileUpload1").val()==""){
			 alert("등록된 파일이 없습니다.");
		 }else{
			 if(confirm("파일을 삭제하시겠습니까?")){
				 
				 $("#fileUpload1").val("");
			 }
		 }
	 });

	 $("#fileDelete2").click(function(){
		 if($("#fileUpload2").val()==""){
			 alert("등록된 파일이 없습니다.");
		 }else{
			 if(confirm("파일을 삭제하시겠습니까?")){
				 
				 $("#fileUpload2").val("");
			 }
		 }
	 });
	 
	 
	 /*
	 $("#fileUpload").change(function(){
		//alert($("#fileUpload").length);  //결과값 무조건 1뜸
		$("#fileUpload1").html("<input type=button name=fileDelete1 id=fileDelete1 value='파일삭제'><input type=file name=file[1]>");
		//$("#menu").html($("#menu").html()+"<p>"+$(this).val()+"</p>");
	 });
	 $("#fileUpload1").on("change",function(){
		 $("#fileUpload2").html("<input type=button name=fileDelete2 id=fileDelete2 value='파일삭제'><input type=file name=file[2]>");
	 }); 
	 
	 */
	 
	//취소버튼 눌렀을때 confirm창이 뜬다.
	$("#cancel").click(function(){
		if(confirm("글작성을 취소하시겠습니까?")){
			location.href="${initParam.root}collection/contentList.do"; 
		}
	}) ;
 });
</script>
</head>
<body>

<form action="auth_writeCollection.do" method="post"  enctype="multipart/form-data" id="writeF">
	<table width="550">
		<tr>
			<td align="right">Title</td>
			<td><input size="65" type="text" name="title" id="title"></td>
		</tr>
		<tr>
			<td align="right" valign="top">
				Content
			</td>
			<td>
				<textarea rows="15" cols="57" name="content" id="content" style="resize: none;"></textarea>
			</td>
		</tr>
		<tr>
			<td colspan="3" align="right"><span id="letterCount"></span>/3000자</td>
		</tr>
		<tr>
			<td rowspan="3" align="right" valign="top">File<br>Attachment</td>
			<td>
				<input type="button" name="fileDelete" value="파일삭제" id="fileDelete">
				<input type="file" name="files[0]" id="fileUpload">
			</td>
		</tr>
		<tr>
			<td>
				<input type="button" name="fileDelete" value="파일삭제" id="fileDelete1">
				<input type="file" name="files[1]" id="fileUpload1">
			</td>
		</tr>
		<tr>
			<td>
				<input type="button" name="fileDelete" value="파일삭제" id="fileDelete2">
				<input type="file" name="files[2]" id="fileUpload2">
			</td>
		</tr>
		<tr>
			<td colspan="2" align="right" style="padding-right: 25px;">
				<input type="button" name="cancel" id="cancel" value="취소">
				<input type="submit" value="확인">
			</td>
		</tr>
	</table>
</form>
</body>
</html>